const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
/**
 * 浅复制，将child复制到parent, 会覆盖parent中非object的键值对
 * @param {object} parent 
 * @param {object} child 
 */
const simpleCopy = function(parent, child){
  for(var i in child){
    if(typeof(parent[i]) != 'object' || typeof(child[i]) != 'obj'){
      parent[i] = child
    }
    else{
      simpleCopy(parent[i], child[i])
    }
  }
}

module.exports = {
  formatTime: formatTime,
  simpleCopy: simpleCopy
}
